package com.xiezc.springboot_dht.model;

public enum BeType {
    /**
     *
     */
    number('i', 'e'),
    list('l', 'e'),
    map('d', 'e'),
    string('0', '0'),
    semicolon(':', ':');

    char pre;
    char suffix;
    int len;

    BeType(char pre, char suffix) {
        this.pre = pre;
        this.suffix = suffix;
        this.len = 0;
    }

    BeType(char pre, char suffix, int len) {
        this.pre = pre;
        this.suffix = suffix;
        this.len = len;
    }

    public byte getPre() {
        return (byte)pre;
    }

    public byte getSuffix() {
        return (byte)suffix;
    }

    public static BeType getByPre(byte pre) {
        if (pre == number.pre) {
            return number;
        }
        if (pre == list.pre) {
            return list;
        }
        if (pre == map.pre) {
            return map;
        }
        if (pre == semicolon.pre) {
            return semicolon;
        }
        if (Character.isDigit(pre)) {
            return string;
        }
        return null;
    }

}
